using System;
using System.Collections.Generic;
using System.Text;

namespace codegen.template
{
    public class TSvc
    {
        public static void GenerateSOAP(string SOAPFileName, string SOAPName,string[] SOAPField,string[] SOAPFieldType)
        {
            StringBuilder sb = new StringBuilder();
            string text = TCommon.GeneratePHPHeadComment("","soap."+SOAPName);

            sb.Append(text);
            sb.Append("	$soap->wsdl->addComplexType(	" + Environment.NewLine);
            sb.AppendFormat("	  '{0}',	" + Environment.NewLine,SOAPName);
            sb.Append("	  'complexType',	" + Environment.NewLine);
            sb.Append("	  'struct',	" + Environment.NewLine);
            sb.Append("	  'all',	" + Environment.NewLine);
            sb.Append("	  '',	" + Environment.NewLine);
            sb.Append("	  array(	" + Environment.NewLine);

            for (int i = 0; i < SOAPField.Length; i++)
            {
                sb.AppendFormat("	  '{0}'=>array('name'=>'{0}','type'=>'xsd:{1}'),	" + Environment.NewLine,SOAPField[i],SOAPFieldType[i]);
            }
            sb.AppendFormat("	  '{0}'=>array('name'=>'{0}','type'=>'xsd:{1}')	" + Environment.NewLine, SOAPField[SOAPField.Length - 1], SOAPFieldType[SOAPField.Length - 1]);
            
            sb.Append("	  )	" + Environment.NewLine);
            sb.Append("	);	" + Environment.NewLine);
            sb.Append("?>" + Environment.NewLine);


            text = sb.ToString();

            utility.TextFile.Write(string.Format("soap.{0}.php", SOAPFileName),text);
        
        }



        public static void GenerateGetRegister(string SOAPFileName, string SOAPName)
        {
            StringBuilder sb = new StringBuilder();
            string text = TCommon.GeneratePHPHeadComment("", "register." + SOAPName);

            sb.Append(text);
            sb.Append("	$soap->register(	" + Environment.NewLine);
            sb.AppendFormat("	'Get{0}ByID',	" + Environment.NewLine,SOAPName);
            sb.Append("	array('UserID'=>'xsd:string'),	" + Environment.NewLine);
            sb.AppendFormat("	array('Result'=>'tns:{0}'),	" + Environment.NewLine,SOAPName);
            sb.Append("	'uri:jeegoon',	" + Environment.NewLine);
            sb.AppendFormat("	'uri:jeegoon/Get{0}ByID',	" + Environment.NewLine,SOAPName);
            sb.Append("	'rpc',	" + Environment.NewLine);
            sb.Append("	'encoded'	" + Environment.NewLine);
            sb.Append("	);	" + Environment.NewLine);

            text = sb.ToString();
            utility.TextFile.Write(string.Format("register.get{0}byid.php", SOAPFileName), text);


            //getbyname
            sb = new StringBuilder();
            text = TCommon.GeneratePHPHeadComment("", "register." + SOAPName);
            
            sb.Append(text);
            sb.Append("	$soap->register(	" + Environment.NewLine);
            sb.AppendFormat("	'Get{0}ByName',	" + Environment.NewLine, SOAPName);
            sb.Append("	array('UserName'=>'xsd:string'),	" + Environment.NewLine);
            sb.AppendFormat("	array('Result'=>'tns:{0}'),	" + Environment.NewLine, SOAPName);
            sb.Append("	'uri:jeegoon',	" + Environment.NewLine);
            sb.AppendFormat("	'uri:jeegoon/Get{0}ByName',	" + Environment.NewLine, SOAPName);
            sb.Append("	'rpc',	" + Environment.NewLine);
            sb.Append("	'encoded'	" + Environment.NewLine);
            sb.Append("	);	" + Environment.NewLine);
            sb.Append("?>" + Environment.NewLine);

            text = sb.ToString();
            utility.TextFile.Write(string.Format("register.get{0}byname.php", SOAPFileName), text);

        }



        public static void GenerateSetRegister(string SOAPFileName, string SOAPName)
        {
            StringBuilder sb = new StringBuilder();
            string text = TCommon.GeneratePHPHeadComment("", "register." + SOAPName);

            sb.Append(text);
            sb.Append("	$soap->register(	" + Environment.NewLine);
            sb.AppendFormat("	'Set{0}',	" + Environment.NewLine,SOAPName);
            sb.AppendFormat("	array('User'=>'tns:{0}','Action'=>'xsd:int'),	" + Environment.NewLine, SOAPName);
            sb.AppendFormat("	array('User'=>'tns:{0}'),	" + Environment.NewLine, SOAPName);
            sb.Append("	'uri:jeegoonsvc',	" + Environment.NewLine);
            sb.AppendFormat("	'uri:jeegoonsvc/Set{0}',	" + Environment.NewLine, SOAPName);
            sb.Append("	'rpc',	" + Environment.NewLine);
            sb.Append("	'encoded'	" + Environment.NewLine);
            sb.Append("	);	" + Environment.NewLine);
            sb.Append("?>" + Environment.NewLine);

            text = sb.ToString();
            utility.TextFile.Write(string.Format("register.set{0}.php", SOAPFileName), text);

        }
    }
}
